package com.njupt.sellsec.handler;

import com.njupt.sellsec.exception.GobalException;
import com.njupt.sellsec.exception.SellerAuthorizeException;
import com.njupt.sellsec.result.CodeMsg;
import com.njupt.sellsec.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.naming.AuthenticationException;
import javax.servlet.http.HttpServletRequest;
import java.net.BindException;

/**
 * @Author: XJL
 * @Description:
 * @Date: Create in 15:49 2018/7/28
 * @Modified By:
 **/
@ControllerAdvice
@Slf4j
public class GobalExceptionHandler {

   /* @ExceptionHandler(value = Exception.class)
    public Result<String> handlerException(HttpServletRequest request,Exception e){
        log.info("【handlerException拦截到异常】");
        if (e instanceof GobalException){
            GobalException ex = (GobalException) e;
            return Result.error(ex.getCodeMsg());
        }else if (e instanceof BindException){
            BindException ex = (BindException) e;
           String msg = ex.getMessage();
           return Result.error(CodeMsg.BIND_ERROR);
        }else {
            return Result.error(CodeMsg.SERVER_ERROR);
        }

    }*/

    @ExceptionHandler(value = SellerAuthorizeException.class)
    public String handlerAuthorizeException(){
        log.info("【handlerAuthorizeException拦截到异常】");
        return "redirect:/login/to_login";
    }
}
